package com.vr.xxaiagent.tools;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.vr.xxaiagent.constant.ToolConstant;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

/**
 * 资源下载工具
 *
 * @author hzh
 * @date 2025/06/04
 */
public class ResourceDownloadTool {

    @Tool(description = "Download a resource from a given URL")
    public String downloadResource(@ToolParam(description = "URL of the resource to download")String url,
                                   @ToolParam(description = "Name of file to save the downloaded resource") String fileName) {
        String fileDir= ToolConstant.FILE_SAVE_DIR+"/download";
        String filePath = fileDir + "/" + fileName;
        try {
            // 创建目录
            FileUtil.mkdir(fileDir);
            // 下载资源
            HttpUtil.downloadFile(url, filePath);
            //TODO: 这里可以将文件上传到云存储服务里
            return "Resource downloaded successfully to:"+  filePath;
        } catch (Exception e) {
            return "Error downloading resource：" + e.getMessage();
        }

    }
}
